From ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 10 Mar 2015 22:19:03 +0000 Subject: Fixed Sequence Generator for IntGen --- src/Generating/BioGen.cpp | 6 +++--- src/Generating/IntGen.h | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index a830f6a43..c9561cc09 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -1000,9 +1000,9 @@ public: std::make_shared> (a_Seed + 101, bgIce, bgTemperate, 150, std::make_shared> (a_Seed + 2000, 200, std::make_shared> (a_Seed + 9, 50, bgOcean, - std::make_shared> (a_Seed + 10, - std::make_shared> (a_Seed + 100, 30 - ))))))))))))))))))))))))))))))); + std::make_shared> (a_Seed + 100, 30) + >> MakeIntGen> (a_Seed + 10) + ))))))))))))))))))))))))))))); m_Gen = std::make_shared>(a_Seed, diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 4fce3ba08..1ffc15c6b 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -70,15 +70,20 @@ public: }; -template -struct PackToInt -{ - enum - { - value = size - sizeof...(Args), - }; +// Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer + +template +struct seq { }; + +template +struct gens : gens { }; + +template +struct gens<0, S...> { + typedef seq type; }; + template class cIntGenFactory { @@ -91,16 +96,23 @@ public: m_args(std::make_tuple(std::forward(a_args)...)) { } - + template std::shared_ptr construct(LhsGen&& lhs) { - return std::make_shared(std::get::value>(m_args)..., std::forward(lhs)); + return construct_impl(std::forward(lhs), typename gens::type()); } + private: std::tuple m_args; + template + std::shared_ptr construct_impl(LhsGen&& lhs, seq) + { + return std::make_shared(std::get(m_args)..., std::forward(lhs)); + } + }; template -- cgit v1.2.3